package com.mcptt.db.op;

import android.content.ContentResolver;
import android.content.Context;
import android.os.RemoteException;

import com.mcptt.db.DbConst;

public class DbOperator {

	public static String THIS_FILE = "DbOperator";
	private Context ctx = null;
	private AddrDbOperator addressDbOperator = null;
	private GroupMembsDbOperator groupMembsDbOperator = null;
	private HistoryDbOperator historyDbOperator = null;
	private MapDbOperator mapDbOperator = null;



	public DbOperator(Context ctx)
	{
		this.ctx = ctx;
		this.addressDbOperator = new AddrDbOperator(ctx);
		this.groupMembsDbOperator = new GroupMembsDbOperator(ctx);
		this.historyDbOperator = new HistoryDbOperator(ctx);
		this.mapDbOperator = new MapDbOperator(ctx);
	}
	
	
	public void resetTables()
	{
		ContentResolver cr = ctx.getContentResolver();
		
		cr.delete(DbConst.MEMBER_URI, null, null);
		cr.delete(DbConst.ADDRESS_URI, "1=1", null);
		cr.delete(DbConst.GROUP_ADDRESS_URI, "1=1", null);
		cr.delete(DbConst.HISTORY_URI, "1=1", null);
		cr.delete(DbConst.SESSION_URI, "1=1", null);
		cr.delete(DbConst.MAP_POINT_URI, "1=1", null);
		cr.delete(DbConst.CONFIG_URI, "1=1", null);
//		cr.delete(DbConst.LOCATION_TRACK_URI, "1=1", null);
		cr.delete(DbConst.LOGIN_URI, "1=1", null);
	}
	public void doExit()  throws RemoteException
	{
		groupMembsDbOperator.resetGrpMemCallState();
		
		groupMembsDbOperator = null;
		addressDbOperator = null;
		historyDbOperator = null;
		mapDbOperator = null;
	}
	
	public AddrDbOperator getAddressDbOperator() {
		return addressDbOperator;
	}

	public GroupMembsDbOperator getGroupMembsDbOperator() {
		return groupMembsDbOperator;
	}

	public HistoryDbOperator getHistoryDbOperator() {
		return historyDbOperator;
	}
	
	public MapDbOperator getMapDbOperator() {
		return mapDbOperator;
	}
}
